import { defineConfig, loadEnv } from "vite";
import path from "path";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";

import VueDevTools from "vite-plugin-vue-devtools";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import { viteMockServe } from "vite-plugin-mock";
// import basicSsl from "@vitejs/plugin-basic-ssl";

// import envCompatible from 'vite-plugin-env-compatible';
// import { createHtmlPlugin } from 'vite-plugin-html';
// import { viteCommonjs } from '@originjs/vite-plugin-commonjs';
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd()); 
  return {
    // base: env.VITE_BASE_PATH,
    resolve: {
      alias: [
        {
          find: /^~/,
          replacement: "",
        },
        {
          find: "@",
          replacement: path.resolve(__dirname, "src"),
        },
      ],
      extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
    },
    plugins: [
      vue({
        script: {
          defineModel: true,
        },
      }),
      vueJsx(),
      VueDevTools(),
      AutoImport({
        imports: [
          "vue",
          {
            "naive-ui": [
              "useDialog",
              "useMessage",
              "useNotification",
              "useLoadingBar",
              "useModal",
            ],
          },
        ],
      }),
      Components({
        resolvers: [NaiveUiResolver()],
      }),
      viteMockServe({
        mockPath: "./src/mock",
        enable: true,
      }),
      // viteCommonjs(),
      // envCompatible(),
      // createHtmlPlugin({
      //   inject: {
      //     data: {
      //       title: 'base-framework'
      //     }
      //   }
      // })
      // basicSsl(),
    ],
    build: {},
    // server: {
    //   host: "0.0.0.0",
    //   https: true,
    // },
  };
});
